package com.service.atf.reply.service;

import com.service.atf.base.exception.TFException;
import com.service.atf.base.model.Account;
import com.service.atf.base.model.TFGameComplate;
import com.service.atf.base.utils.ATFConstants;
import com.service.atf.base.utils.ATFLogger;
import com.service.atf.reply.ac.AccountManager;
import com.service.atf.reply.core.IReadExecutor;
import com.luotao.devp.base.utils.MD5Util;

import java.util.Map;

/**
 * User: luotao
 * Date: 12-3-21
 * Time: 17:00:00
 */
public class GameCompleteService10 implements IReadExecutor<TFGameComplate> {
    private static final String KEY_TMP_AWARD = "tmpAward";

    @Override
    public boolean isNotify() {
        return true;
    }

    public void initOut(Map out) {
        out.put(KEY_TMP_AWARD, 0);
    }

    @Override
    public void execute(boolean recover, AccountManager accountManager, TFGameComplate gameComplate, Map out) {
        ATFLogger.sysdebug("enter gameComplete");
        //    Validata.validataCustomerCode(this, gameComplate.getCustomerCode());
        long awardMoney = gameComplate.getTempAwardMoney();
        Account account = accountManager.getBussAccount(gameComplate.getCustomerCode());

        //   Validata.validataACNull(this, gameComplate.getCustomerCode(), account);
        String md5Bingo = MD5Util.MD5Encode(gameComplate.getMapFlowId() + awardMoney);
        if (!account.getMd5Bingo().equals(md5Bingo)) {
            String msg = "" + gameComplate.getCustomerCode();
            ATFLogger.sysdebug(msg);
            throw new TFException(ATFConstants.ATF_BINGO_MD5_ERR, msg);
        }
        ATFLogger.sysdebug("current temp award : " + account.getTmpAward() + " this awardMoney : " + awardMoney);

        account.setTmpAward(account.getTmpAward() + awardMoney);
        account.setLastFlowId("");
        accountManager.updateAccount(account);
        out.put(KEY_TMP_AWARD, account.getTmpAward());

    }
}
